package mapEditor.interactor;

//import debug.*;
	
import mapEditor.map.MapCanvas;
import mapEditor.utils.MapLocation;
import mapEditor.utils.Util;

import java.awt.Graphics2D;


// ********************************************************************
// *** CLASS: LineMouseAdapter
// ********************************************************************
public class MeasureInteractor extends MapInteractorAdapter
{ public String getMouseModeMnemonic() { return("Measure"); }
  private boolean measuring;

  // ******************************************************************
  // *** CONSTRUCTOR: LineMouseAdapter
  // ******************************************************************
  public MeasureInteractor(MapCanvas mapCanvas)
  { super(mapCanvas,MEASURE);  
    this.measuring=false;
  }

  // ******************************************************************
  // *** METHOD: paintMouseEffect
  // ******************************************************************
  public void paintMouseEffect(Graphics2D g)
  {	if(measuring) { Util.drawLine(g,mouseStart,mouseCurrent); }
  }

  // ******************************************************************
  // *** METHOD: mouseDragged
  // ******************************************************************
  // Invoked when a mouse button is pressed and then dragged.
  protected void mouseDragged() { if(measuring) mapCanvas.repaint(); }


  // ******************************************************************
  // *** METHOD: mouseMoved
  // ******************************************************************
  // Invoked when the mouse has been moved (with no buttons down).
  protected void mouseMoved() {}

  // ******************************************************************
  // *** METHOD: mousePressed
  // ******************************************************************
  // Invoked when a mouse button has been pressed.
  protected void mouseLeftPressed(MapLocation p)
  { if(!measuring) { measuring=true; mouseStart=p; } }
  protected void mouseRightPressed(MapLocation p) {}

  // ******************************************************************
  // *** METHOD: mouseReleased
  // ******************************************************************
  // Invoked when a mouse button has been released.
  protected void mouseLeftReleased(MapLocation p)
  { mapCanvas.measurementDone(mouseStart,p);
    measuring=false; mapCanvas.repaint();
  }
  protected void mouseRightReleased(MapLocation p) {}

}